package com.ow.dva.util.pay.alipay;

import javax.servlet.http.HttpServletRequest;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @Author: 闫增宝
 * @Description: 支付宝配置
 * @Date: 19-4-23 上午11:16
 */
public class AliPayConfig {


//     应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
    public static String app_id = "2018041760033023";
//     商户私钥，您的PKCS8格式RSA2私钥
    public static String merchant_private_key = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCWoebsqGNpB7Ux1s5sqx3NQ16e+petkmWKcNJJCu/oxpmAW4mjTCuGkcYpHnOqbecp6Uc/9y3HF8zPOSwK+FODHiRxTcSC7rvR5hyPjnkh0cn7qZojLWt15A0Y2sjjgnTGKTUOBAmrbxU42Nn+X+gLzjzseuq6AHF5JYznLsKHEUiF0ivWGYRznrNPRMVTpVPFxawmZBlBvcEZdsAKkT55J7dJhkK3fFe65V00P582LM0nBHdWREJdQkID5x1MVL7eM31X53mZwA6ZY6VOKNKHmoC3QX0S2fvROL2wZ1tNMfauFrJGasQFHqbr1gotFdeANN1diaHHCB+f3BgDoEJnAgMBAAECggEAAP7G2M9wALSlVNP3fy5OPxnv2RsMv3/VHeoK6aKh3SbawsdYDHUnYHc8GO9zki+xtEwvRVPrwIH+v2vAR75GRvp/ASSjZL4RDZz4mVY2pKuPKxN+yja1nAzKrVxcsWweO2TwTcxnB/Pu7vY30n9tuA4/xsw1Gs9/8G34FVrwvBW1fhJX7RhlVxvQK53JVowXxp1/7F8+VGYoZg/aZ0fZ+iGboaxRnlm2dpk9Mhcym5H/OcFmyesJBgHhGJULfY9pZ1qoxg3Z+q6/+i3JhiAvVK6KSKCOTIplgvgCVqxan2v9m9fU7j6AuGJtNtbzZ40N/ESpfrpVgbSGnVkiztuYMQKBgQDzyGxTP+rLPdmYL8nj8JijfR2mvh59g6ql6vRNw0OT2YWMJerzPPg2mNjxLCyAAc1/SVrJEy4QoXJiAWBLv70oTP9sxcCTXuZqRuaNNNx99Lzad+VfvqY4N+6CCNtGB1TXd/jySYZAAylP+SoKUmIBA1KE3uKqXSdXIurHIfZnqQKBgQCeLmsrGT5t04k6NDLHLP5O54heKq+dIuK+0iE15QJtvNlK5iYTXohgzRaYLa4zcYCIixyly8N1G6XWRwZ632vb4Ps7Tvla+fnE4bRA8du6V9HYZxESoT3ItC2sLMEeRheij7jIz7QOa7NcHI0chxGGe1Giwicfl/ls7D190XZjjwKBgDIYHkJhIQNQm1UNhOQE/aiiviQUbzmFg9yCUl9kX4+TJEEvTX9cKPk3IWU1mZNYS3z7et9UxKOAOXvwInSOWvVcFSSp4i+mUZzHIvsjQKfVUbVm68hn6colnCo2XbCfMwzvx0UqXJ7sx2F6puvmD+N7ZkqNbnBpofri3vG6heK5AoGASJPXzECa6l1i23fTzJuSW7XUVhCT3y+Ahjl3z3iyMpOxx7HtynlXbcLsGQrsoOH1LbFWhaQGnJcA8l5IVNxqasrBuyazNtD3jyRYRmwyez+MIxS3OqsM5Cf3xMYMHc3fTlFPYaQbY3p7I0peXLaEjgXLITigJtjeMuH6HN6cyXUCgYBe8altRjiikFxnz7t3qYJZJsG44mTLEC157VGIV+XMbRd0q92lVlulkGGKrbaY4zzZ5SiwdYp7CHnZrqpVsV+6fQoaGBQWY6tn0pHqo6QI+kNkqBmJvz0RR/8b8b/vzMECxrpIgJEn/ZEI+v9ehh40uYeQTut1ubH5mYVELQp1Ew==";
//     支付宝公钥
    public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkwrCqWS8v/t6FneNPOalZl85bFldoXzeqZaZE88WmubzgVGEhL/V3qEtuTFy0TnkO/Vs+TJh8mq/tPLDVce0iQhNvpXQOkO1YgM4S0ZNIPiroxzwVHvKpxtMWIPFfcUM+iUHHuCBFKIDwFMibq3GwXQbJSkbWAdH9ltUx5HkgTKTj2HEo+KlGxKFoFK4YhUuW55MVIaED750wGOT46Be/NALT8nmQKFSk72TmlaJObuOywkvHMor5pJMG6hPG2+3NBnpY/a2AG7Hs9HI6z2eCnGMBe3Ou/bgLlJ0wA9igj6beZXLGJ4YzBzwMbau3LUJXJIACyYpRB4eeSV2CVFJtwIDAQAB";

    // 签名方式
    public static String sign_type = "RSA2";

    // 字符编码格式
    public static String charset = "utf-8";

    // 支付宝网关
    public static String gatewayUrl = "https://openapi.alipay.com/gateway.do";

    // 支付宝网关
    public static String log_path = "/home/";

    //包月回调路径(本地)
    //public static String notify_url_monthly = "http://onlygx.320.io:8780/app/alipay/notifyUrlMonthly";

//    包月回调路径
    public static String notify_url_monthly = "https://zhsq.lianxinyi.com.cn:18447/app/alipay/notifyUrlMonthly";
    
    //public static String return_url_monthly = "http://192.168.1.87:8080/app/alipay/returnUrlMonthly";

    //扫码支付回调
    public static String notify_app_url= "https://zhsq.lianxinyi.com.cn:18447/app/order/appNotify";

    /**
     * @Author: 闫增宝
     * @Description: 封装回调获取参数的方法
     * @Date: 19-4-23 上午11:40
     */
    public static Map<String, String> gainParameter(HttpServletRequest request) {
        Map<String, String> params = new HashMap<String, String>();
        Map<String, String[]> requestParams = request.getParameterMap();
        for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) ? valueStr + values[i]
                        : valueStr + values[i] + ",";
            }
            params.put(name, valueStr);
            //System.out.println(name +"------------" + valueStr);
        }
        return params;
    }


    /**
     * 写日志，方便测试（看网站需求，也可以改成把记录存入数据库）
     * @param sWord 要写入日志里的文本内容
     */
    public static void logResult(String sWord) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis() + ".txt");
            writer.write(sWord);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


}
